package fileshare.datastructure;

public class MsgQue
{
	
	Msg []msgrow=new Msg[30000];
	int msgno=0;
	String type;
	public MsgQue(String tp)
	{
		type=tp;
	}
	
	public synchronized void add(byte[]n,int length)
	{
		Msg m=new Msg(n,length);
		msgrow[msgno]=m;
		//System.out.println("a message is added to"+type+" the lenth is "+msgrow[msgno].msglength+"into slot"+msgno+" this object is "+this.toString()+"thread is"+Thread.currentThread());
		msgno++;
		//System.out.println("msgno is"+msgno);
	}
	public synchronized Msg remove()
	{
		if(msgno>0)
			{msgno--; 
			//System.out.println("msgno is"+msgno);
			//System.out.println("a message is removed from "+type+"the lenth is "+msgrow[msgno].msglength+"at slot"+msgno+" this object is "+this.toString()+"thread is"+Thread.currentThread());
			return msgrow[msgno];}//newchange
		else
			return null;
		
	}

}
